package com.xm.adv.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;

import com.bigkoo.convenientbanner.holder.Holder;
import com.xm.adv.R;

import java.io.File;

import xinya.com.baselibrary.bean.program.ResourcesBean;
import xinya.com.baselibrary.utils.GlideApp;
import xinya.com.baselibrary.utils.LogUtil;

public class CrossBannerImgHolderView implements Holder<ResourcesBean> {

    ResourcesBean data;

    private ImageView imageView;

    public CrossBannerImgHolderView() {
    }

    @Override
    public View createView(final Context context) {
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setBackgroundColor(ContextCompat.getColor(context,R.color.black));
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                new TypeDataContorl(context, data.getJumpType(), data.getTitle(), data.getJumpDataMaps())
//                        .to();
            }
        });
        return imageView;
    }

    @Override
    public void UpdateUI(final Context context, final int position, ResourcesBean data) {
        this.data = data;
        LogUtil.LogShitou("CrossBannerImgHolderView--UpdateUI", ""+data.getFilePath());
        LogUtil.LogShitou("CrossBannerImgHolderView--UpdateUI", ""+data.getDownloadurl());
        try {
            GlideApp.with(context)
                    .load(new File(data.getFilePath()))
                    .centerCrop()
                    .placeholder(R.mipmap.ic_empty)
                    .into(imageView);
        } catch (Exception e) {
            imageView.setImageResource(R.mipmap.ic_empty);
        }
    }
}